<script src="./equal.js"></script>
<script>
  {
    const typeOfMap = 'function'
    console.assert(typeOfMap === typeof Map)
  }
  {
    const map = new Map()
    map.set('key','value')
    const value = map.get('key')
    console.assert(value === 'value')
  }
  {
    const map = new Map()
    map.set('key', 'value')
    const hasIt = map.has('key')
    console.assert(hasIt === true)
  }
  {
    const map = new Map([['key', 'value']])
    map.delete('key')
    console.assert(map.size === 0)
  }

  {
    const map = new Map([['key', 'value']])
    console.assert(equal(Array.from(map.keys()), ['key']))
    console.assert(equal(Array.from(map.values()), ['value']))
  }

  {
    const map = new Map([['one', 'uno']])
    for (let [key, value] of map) {
      console.assert(key === 'one')
      console.assert(value === 'uno')
    }
  }

  {
    const map = new Map()
    map.set('1', 'one')
    map.set('2', 'two')
    const mapAsArray =[...map.entries()]  // hint: kata #29 http://tddbin.com/#?kata=es6/language/array-api/from
    console.assert(
      equal(mapAsArray, [
        ['1', 'one'],
        ['2', 'two'],
      ])
    )
  }
  {
    const obj = { x: 1 }
    const otherObj = { x: 1 }
    const map = new Map()
    map.set(obj, {x:1})
    // map.set(otherObj,{x:1})
    console.assert(map.has(otherObj) === false)
  }

  {
    let map = new Map()
    map.set('key', 'value')
    const value = map.get('key')
    console.assert(value === 'value')
  }
  {
    let map = new Map()
    map.set(map.set(map.set('value', 'value')))
    var value = map.get(map.get(map.get('value')))
    console.assert(value === 'value')
  }

  {
    let map = new Map()
    const obj = {}
    map.set(obj, 'object is key')
    console.assert(map.get(obj) === 'object is key')
  }

  {
    let map = new Map()
    map.set(void 0, 'yo')
    const value = map.get(void 0)
    console.assert(value === 'yo')
  }

  {
    let map = new Map()
    map.set(void 0, void 0)
    const value = map.get(void 0)
    console.assert(value === void 0)
  }

  {
    let map = new Map()
    map.set('key','value')
    console.assert(map.get('key') === 'value')
  }

  {
    const noop = function () {}
    let map = new Map()
    map.set(noop, 'the real noop')
    map.get(noop)
    console.assert(map.get(noop) === 'the real noop')
  }

  {
    let map = new Map()
    map.set('key', 'value')
    map.set('key', 'value1')
    console.assert(map.get('key') === 'value1')
  }
  {
    let map = new Map()
    map.set(1, 'one').set(2, 'two').set(3,'three')
    console.assert(equal([...map.keys()], [1, 2, 3]))
    console.assert(equal([...map.values()], ['one', 'two', 'three']))
  }
</script>
